<?php
class heartmanager extends CI_Model {

    public function __construct()
    {
        $this->load->database();
		$this->load->model('util');
		$this->load->model('usermanager');
    }
	public function get_heart()
	{
		$query = $this->db->get_where('user', array('sxAcount' => $sxAcount));
		return $query->row_array();
	}
	public function app($user,$ip='192.168.1.1',$time,$appModel,$sign,$mac){
		//$keySign='5c1830a49f1afecc2351d01483f35308';
		$keySign='cd84ed03e3e8ef3afd43dd417c6bb2aa';
		if(time()-$time>=30){
			return $this->util->format_return(1,2,"out of date",null);	
		}
   
		$data=array('data'=>base64_encode($this->get_pack($user,$ip)),'sendIp'=>'115.239.134.167','sendPort'=>8080);
		return $this->util->format_return(1,1,"success",$data);	
	}
	public function router($user = '',$ip='192.168.1.1')
	{
		$data=array("packData"=>base64_encode($this->get_pack($user,$ip)),'sendIp'=>'115.239.134.167','sendPort'=>8080);
		$a=array("status"=>200,"data"=>$data);
		return $a;
	}
    public function desk_app($user = '',$ip='192.168.1.1')
	{
		$data=array("status"=>200,"packData"=>base64_encode($this->get_pack($user,$ip)),'sendIp'=>'115.239.134.167','port'=>8080);
		return $data;
	}
	public function shell($user = '',$ip='192.168.1.1')
	{
        //$data=array("fromIp"=>$ip,"packData"=>,'sendIp'=>'115.239.134.167','port'=>8080);
		return base64_encode($this->get_pack($user,$ip));
	}
	public function get_pack($user = '',$ip='192.168.1.1')
	{
     	$url="http://2.shanxunkiller.applinzi.com/getheart/?user=".$user.'&ip='.$ip;
		return file_get_contents($url);	
	
	}
	private function isCloneMacAddress($row,$ip){
		$ip1=$row['ip1'];
		$ip2=$row['ip2'];
		$ip1_date=$row['ip1_date'];
		$ip2_date=$row['ip2_date'];
		if($ip1_date-$ip2_date>0){
			if($ip==$ip1){
				return 1;
			}else if($ip==$ip2){
				return 0;
			}else{
				return 2;
			}
		}else{
			if($ip==$ip2){
				return 1;
			}else if($ip==$ip1){
				return 0;
			}else{
				return 3;
			}
		}
	}
	private function get_user_info($sxAcount){
		$query = $this->db->query('SELECT * FROM user where sxAcount="'.$sxAcount.'" ');
		$row = $query->row_array();
		return $row;
	}
}